#!/usr/bin/python

import os
import os.path
import shutil
import sys
from cx_Freeze import setup, Executable

def make_zoneinfo_zip_truple(source, dest):
    file_list = []
    path_list = os.listdir(source)
    for i in xrange(0, len(path_list)):
        if os.path.isfile(source + "/" + path_list[i]):
            file_list.append((source + "/" + path_list[i], dest + "/" + path_list[i]))
        elif os.path.isdir(source + "/" + path_list[i]):
            tmp_list  = make_zoneinfo_zip_truple(source + "/" + path_list[i], dest + "/" + path_list[i])
            file_list = file_list + tmp_list
    return file_list

dir      = os.getcwd()
bin_path = dir + "/dist/usr/local/foxhound/bin/mscheduler/"
shutil.rmtree(bin_path, True)
zip_includes_list = []
zoneinfo_truple   = make_zoneinfo_zip_truple(dir + "/resources/pytz/zoneinfo","pytz/zoneinfo")
zip_includes_list = zip_includes_list + zoneinfo_truple
setup(name        = "mscheduler",
      version     = "0.1 alpha",
      description = "a scheduler for running class",
      options     = {
                      "build_exe"  : {
                                       "build_exe" : bin_path,
                                       "optimize"  : 0,
                                       "includes"  : ["MySQLdb","apscheduler","pytz","tzlocal"],
                                       "packages"  : [
                                                      "os",
                                                      "sys",
                                                      "service",
                                                      "pytz",
                                                      "tzlocal"
                                                     ],
                                       "zip_includes":zip_includes_list
                                     },
                      "install_exe" : {
                                       "build_dir"   : bin_path,
                                       "install_dir" : bin_path 
                                      }
                  },
      executables = [
                     Executable(
                                "main.py", 
                                path       = ["/usr/lib","/usr/lib64"],
                                targetName = "mscheduler",
                                targetDir   = bin_path,
                                includes   = ["MySQLdb","apscheduler","pytz","tzlocal"]
                               )
                    ]
     )
